package com.wrial.simple;
/*
 * @Author  Wrial
 * @Date Created in 21:41 2020/3/23
 * @Description  LeetCode1
 */

import java.util.HashMap;
import java.util.Map;

public class LeetCode_01 {
    public static void main(String[] args) {

        int[] nums = {7,3,2};
        int target = 9;
        int[] ints = new LeetCode_01().twoSum(nums, target);
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }


    // 可以此案有

    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> hashMap = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            int temp = target - nums[i];
            if (hashMap.containsKey(temp)) {
                return new int[]{hashMap.get(temp),i};
            }
            hashMap.put(nums[i], i);
        }

        return null;
    }
}







